import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('bg')
export class bg extends Component {

    @property(Node)
    bg01: Node = null;

    @property(Node)
    bg02: Node = null;

    @property
    speed: number = 100;

    start() {

    }

    update(time: number) {
        //实现对于bg01移动 向下方移动
        let postion1 = this.bg01.position;
        this.bg01.setPosition(postion1.x, postion1.y - this.speed * time, postion1.z)
        let postion2 = this.bg02.position;
        this.bg02.setPosition(postion2.x, postion2.y - this.speed * time, postion2.z)

        //实现p1 或者p2其中有一个移除屏幕,另一个图片要移动到图片的上方
        let p1 = this.bg01.position;
        let p2 = this.bg02.position;
        if (this.bg01.position.y < -852) {
            this.bg01.setPosition(p2.x, p2.y + 852, p2.z);
        }
        if (this.bg02.position.y < -852) {
            this.bg02.setPosition(p1.x, p1.y + 852, p1.z)
        }
    }
}


